package GUI;
import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import source.Client;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ClientFrame extends javax.swing.JFrame {
	private boolean isadmin = false;
	private Client tempclient = null;
	private JTabbedPane jTabbedPane1;
	private JPanel jPanel1;
	private JPanel jPanel2;
	
	public ClientFrame(Client tempclient) 
	{
		super();
		if(tempclient != null && tempclient.getClass() != null)			
			this.isadmin = tempclient.getClientuser().isAdmin();
		this.tempclient = tempclient;
		initGUI();
		setLocationRelativeTo(null);
		setVisible(true);
	}
	
	private void initGUI() {
		try {
			setTitle("Kino");
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			{
				jTabbedPane1 = new JTabbedPane();
				getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
				{
					jPanel1 = new UserPanel(tempclient, this);
					jTabbedPane1.addTab("UserFrame", null, jPanel1, null);
					if(isadmin)
					{
						jPanel2 = new AdminPanel(tempclient);
						jTabbedPane1.addTab("AdminFrame", null, jPanel2, null);
					}
				}
			}
			addWindowListener(new WindowListener() {
				
				@Override
				public void windowOpened(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowIconified(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowDeiconified(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowDeactivated(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowClosing(WindowEvent arg0) 
				{
					if(tempclient != null)
						tempclient.logout();
				}
				
				@Override
				public void windowClosed(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowActivated(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
			});
			pack();
			setSize(1300, 800);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void closeClientFrame(){
		setVisible(false);
	    dispose();
	}
	
}
